#!/usr/bin/env node
//服务器
//url:http://localhost:8080/add?x=2&y=3
//
const http = require('http'),
  url = require('url'),
  qs = require('querystring');
  
http.createServer((req,res)=>{
  const addr = url.parse(req.url);
  if(addr.pathname === '/add'){
    const arg = qs.parse(addr.query);
    const r = {};
    r.add = Number(arg.x) + Number(arg.y);
    res.end(JSON.stringify(r));
    //console.log(qs.parse(addr.query));
  }
  //console.log(url.parse(req.url));
  //res.end('ok');
}).listen(8080);
